//
//  SAWarehousingDetailCell.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/5/25.
//

#import "SAWarehousingDetailCell.h"
#import "SASalesOrderViewListModel.h"

@interface SAWarehousingDetailCell ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *colourSizeLab;
@property (nonatomic, strong) UILabel *numLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UILabel *totalPriceLab;

@end

@implementation SAWarehousingDetailCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

-(void)setModel:(SASalesOrderToPendSkuList *)model {
    _model = model;
    self.titleLab.text = [NSString stringWithFormat:@"%@,%@",model.colourName,model.sizeName];
    self.numLab.text = model.count;
    self.priceLab.text = [NSString stringWithFormat:@"%0.2f",[model.price floatValue]/100.f];
    CGFloat totalPrice = [model.price floatValue]/100.f * [model.count floatValue];
    if (totalPrice == 0) {
        self.totalPriceLab.text = @"0.00";
    }else {
        self.totalPriceLab.text = [NSString stringWithFormat:@"%0.2f",totalPrice];
    }
    if ([model.count floatValue] < 0) {
        self.titleLab.textColor = kPinkColor;
        self.numLab.textColor = kPinkColor;
        self.priceLab.textColor = kPinkColor;
        self.totalPriceLab.textColor = kPinkColor;
    }else {
        self.titleLab.textColor = kBlackColor;
        self.numLab.textColor = kBlackColor;
        self.priceLab.textColor = kBlackColor;
        self.totalPriceLab.textColor = kBlackColor;
    }
    
    NSString *productViewCostPrice = [NSString stringWithFormat:@"%@",[SAValueManger shareInStance].userInfo.menuList[1][@"perms"][@"productViewCostPrice"]];
    if ([productViewCostPrice isEqualToString:@"1"]) {
        self.priceLab.text = @"******";
        self.totalPriceLab.text = @"******";
    }
}

-(void)setProductModel:(SASalesOrderToPendSkuList *)productModel {
    _productModel = productModel;
    self.titleLab.text = [NSString stringWithFormat:@"%@,%@",productModel.colourName,productModel.sizeName];
    self.numLab.text = productModel.count;
    self.priceLab.text = productModel.stock;;
    self.totalPriceLab.text = [NSString stringWithFormat:@"%zd",[productModel.stock integerValue] - [productModel.count integerValue]];
}

-(void)initUI {
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.colourSizeLab];
    [self.contentView addSubview:self.numLab];
    [self.contentView addSubview:self.priceLab];
    [self.contentView addSubview:self.totalPriceLab];
}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(20, 0, 125, 40)];
        _titleLab.textColor = kBlackColor;
        _titleLab.font = kFont(13);
    }
    return _titleLab;
}

-(UILabel *)numLab {
    if (!_numLab) {
        _numLab = [[UILabel alloc] initWithFrame:SARectMake(150, 0, 70, 40)];
        _numLab.textColor = kBlackColor;
        _numLab.font = kFont(13);
        _numLab.textAlignment = NSTextAlignmentCenter;
    }
    return _numLab;
}

-(UILabel *)priceLab {
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] initWithFrame:SARectMake(225, 0, 70, 40)];
        _priceLab.textColor = kBlackColor;
        _priceLab.font = kFont(13);
        _priceLab.textAlignment = NSTextAlignmentCenter;
    }
    return _priceLab;
}

-(UILabel *)totalPriceLab {
    if (!_totalPriceLab) {
        _totalPriceLab = [[UILabel alloc] initWithFrame:SARectMake(300, 0, 70, 40)];
        _totalPriceLab.textColor = kBlackColor;
        _totalPriceLab.font = kFont(13);
        _totalPriceLab.textAlignment = NSTextAlignmentCenter;
    }
    return _totalPriceLab;
}


@end
